#include <iostream>
#include <string>
#include <unordered_map>
#include <cmath>

bool is_prime(int num) {
    if (num <= 1) return false;
    for (int i = 2; i <= std::sqrt(num); ++i) {
        if (num % i == 0) return false;
    }
    return true;
}

int closest_prime(int num) {
    int lower = num, upper = num;
    while (true) {
        if (is_prime(lower)) return lower;
        if (is_prime(upper)) return upper;
        --lower;
        ++upper;
    }
}

int main() {
    std::unordered_map<std::string, int> words_to_numbers = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };

    std::string word;
    int number = 0;
    for (int i = 0; i < 3; ++i) {
        std::cin >> word;
        if (words_to_numbers.find(word) == words_to_numbers.end()) {
            std::cout << "Wrong input";
            return 0;
        }
        number = number * 10 + words_to_numbers[word];
    }

    std::cout << closest_prime(number);
    return 0;
}